Imports System.Drawing
Imports System.IO

Public Class ImageListDemo
    Dim dirName As String = "C:\VB2005.2\Ch5\images"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dirName = InputBox("Image Folder", "Chọn thư mục")
        If dirName <> "" Then
            Dim imgFiles As String() = System.IO.Directory.GetFiles("C:\VB2005.2\Ch5\images\", "*.*")
            Dim i As Integer = 0
            For Each f As String In imgFiles
                Dim iPos As Integer = f.LastIndexOf("\")

                If f.IndexOf(".gif") > 0 Or f.IndexOf(".jpg") > 0 Then
                    Dim img As Image = System.Drawing.Image.FromFile(f)
                    Me.ImageList1.Images.Add(img)

                    Dim item As ListViewItem = Me.ListView1.Items.Add(f.Substring(iPos + 1))
                    item.ImageIndex = i
                    i = i + 1
                End If
            Next
        End If

    End Sub

    Private Sub ImageListDemo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.ListView1.View = View.LargeIcon
        Me.ListView1.LargeImageList = ImageList1
        ImageList1.ImageSize = New Size(80, 80)
        ImageList1.ColorDepth = ColorDepth.Depth24Bit

    End Sub
End Class
